import classes from './TextInput.module.css'
import socket from '../../ws'
import {useRef} from "react";
import {useSelector} from "react-redux";

function TextInput(){

    const myRef = useRef();
    const {me} = useSelector(state => state.user)

    //发送消息
    function btn(){
        let msg = myRef.current.value;
        let date = new Date();
        socket.emit('send',{
            username:me.username,
            avatar:me.avatar,
            date:date,
            msg:msg
        })
    }

    return(
        <div className={classes.box}>
            <textarea className={classes.textarea} ref={myRef}></textarea>
            <button className={classes.btn} onClick={btn}>发送</button>
        </div>
    )
}
export default TextInput;